package com.example.avmanagerweb.controller;


import com.example.avmanagerweb.entity.Fence;
import com.example.avmanagerweb.entity.Fenceshape;
import com.example.avmanagerweb.entity.Fenceshapepos;
import com.example.avmanagerweb.entity.vo.FenceGraphVo;
import com.example.avmanagerweb.entity.vo.FenceListVo;
import com.example.avmanagerweb.entity.vo.FencePTVo;
import com.example.avmanagerweb.entity.vo.FenceVo;
import com.example.avmanagerweb.result.RLIST;
import com.example.avmanagerweb.service.FenceService;
import com.example.avmanagerweb.service.FenceshapeService;
import com.example.avmanagerweb.service.FenceshapeposService;
import com.example.avmanagerweb.service.SysDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xg
 * @since 2023-06-27
 */
@RestController
@RequestMapping("/fence")
public class FenceController {
    @Autowired
    private FenceService fenceService;


    @PostMapping(value = "/addFence")
    public RLIST addFence(@RequestBody FenceVo fenceVo) {
        boolean b = fenceService.addFence(fenceVo);
        if(b){
            return RLIST.ok();
        } else {
            return RLIST.error();
        }
    }

    @PostMapping(value = "/addFenceGraph")
    public RLIST addFenceGraph(@RequestBody FenceGraphVo fenceGraphVo) {
        boolean b = fenceService.addFenceGraph(fenceGraphVo);
        if(b){
            return RLIST.ok();
        } else {
            return RLIST.error();
        }
    }

    @PostMapping(value = "/alterFence")
    public RLIST alterFence(@RequestBody Fence fence) {
        boolean b = fenceService.updateById(fence);
        if(b){
            return RLIST.ok();
        } else {
            return RLIST.error();
        }
    }

    @DeleteMapping(value = "delFence")
    public RLIST delFence(@RequestParam(value = "fenceId") int fenceId) {
        boolean b = fenceService.deleteFence(fenceId);
        if(b){
            return RLIST.ok();
        } else {
            return RLIST.error();
        }

    }

    @DeleteMapping(value = "delFenceGraph")
    public RLIST delFenceGraph(@RequestParam(value = "fenceId") int fenceId) {
        boolean b = fenceService.deleteFenceGraph(fenceId);
        if(b){
            return RLIST.ok();
        } else {
            return RLIST.error();
        }
    }

    @GetMapping("/getlist")
    public RLIST getlist(@RequestParam(value = "depid") int depid) {
        List<FenceListVo> fenceList = fenceService.getFenceList(depid);
        return RLIST.ok().data("data",fenceList);

    }
}

